//
//  NSArray+YFExtension.m
//  project
//
//  Created by yefei on 2019/4/17.
//  Copyright © 2019 健健. All rights reserved.
//

#import "NSArray+YFExtension.h"

@implementation NSArray (YFExtension)

/**
 根据条件给数组添加数据

 @return 添加好的数据
 */
- (ArrayRefresh)addArray {
    return ^NSArray * _Nullable(NSArray * _Nullable array, BOOL isRefresh){
        NSArray *selfArray = [self copy];
        if (array && array.count > 0) {
            if (isRefresh) { selfArray = array; }
            else { selfArray = [selfArray arrayByAddingObjectsFromArray:array]; }
        }
        return selfArray;
    };
}

- (NSString *)jsonArray {
    
    if (self.count == 0) {
        return  @"";
    } else if (self.count == 1) {
        return [NSString stringWithFormat:@"%@", self.firstObject];
    } else {
        NSString *jsonString = NSString.string;
        for (int i = 0; i < self.count; i++) {
            if (i == self.count - 1) {
                jsonString = [jsonString stringByAppendingString: [NSString stringWithFormat:@"%@", self[i]]];
            } else {
                jsonString = [jsonString stringByAppendingString:[NSString stringWithFormat:@"%@,", self[i]]];
            }
        }
        return jsonString;
    }
}

@end
